/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.yandex.skipass;

import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 *
 * @author Brothers
 */
public class PassForAnDay extends PassForSeason {

    private int topTime;
    private int bottomTime;

    // public Day() {this.bottomTime = -1;this.topTime = -1;}
    public PassForAnDay(int idPass, Enums.PassType typePass,
            Calendar firstDatePass, Enums.Week ogrPass) {
        super(idPass, typePass, firstDatePass, ogrPass);
        this.bottomTime = -1;
        this.topTime = -1;
    }

    public void setDays(int days, int time) {
        this.setNumberDay(days);
        this.setTime(time);
    }

    protected void setTime(int time) {

        this.topTime = Enums.TimeEnum.values()[time].getUpTime();
        this.bottomTime = Enums.TimeEnum.values()[time].getDownTime();

    }

    protected int getTopTime() {
        return this.topTime;
    }

    protected int getBottomTime() {
        return this.bottomTime;
    }

    public boolean isInTimeHours() {
        Calendar date = new GregorianCalendar();
        return this.getBottomTime() <= date.HOUR
                && date.HOUR <= this.getTopTime();
    }

    public boolean isPassForAnDayRight(AccountingSystem sys, int id) {

        if (!this.isValidDate(sys.getDate()) && this.isInTimeHours()) {
            this.blockPass();
            ((Turnstile) sys.getTurn().get(id)).plusAccessFalse();
            return false;
        } else {
            return true;
        }
    }
}
